<script setup lang="ts">
import { onLaunch, onShow, onHide, onLoad } from '@dcloudio/uni-app'
import { useSettingStore } from '@/stores'
import { getSettingApi } from '@/api/common'
import { checkUpdate } from '@/utils/update'

onLaunch(() => {
  console.log('App Launch')

  const settingStore = useSettingStore()
  getSettingApi().then((res) => {
    console.log('Update Setting')
    settingStore.update(res.result)
  })
  
  // Check for app updates
  // #ifdef APP-PLUS
  setTimeout(() => {
    checkUpdate()
  }, 2000)
  // #endif
})
onShow(() => {
  console.log('App Show')

  // #ifdef WEB
  // 隐藏了导航栏，非首页添加历史记录用于返回首页
  let hash = location.hash || '#/'
  if (hash !== '#/') {
    history.pushState({}, '', '#/')
    history.pushState({}, '', hash)
  }
  // #endif
})
onHide(() => {
  console.log('App Hide')
})
</script>

<style lang="scss">
// 字体图标
@import '@/static/alifont/iconfont.css';
[class^='icon-'],
[class*=' icon-'] {
  font-family: 'iconfont' !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

view,
navigator,
input,
scroll-view {
  box-sizing: border-box;
}

button::after {
  border: none;
}

swiper,
scroll-view {
  // flex: 1;
  // height: 100%;
  overflow: hidden;
}

image {
  width: 100%;
  height: 100%;
  vertical-align: middle;
}

// 两行省略
.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

.header-wrap {
  position: fixed;
  top: 0;
}
</style>
